package edu.worldskills.b;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Environment;
import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;

public class Function {

    public static  void saveBitmapToPictures(Bitmap bitmap, Context context) {
        // 获取 Pictures 文件夹路径
        String fileName = UUID.randomUUID().toString();

        // 获取Pictures路径
        File picturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

        // 创建目标文件
        File file = new File(picturesDir, fileName + ".png");
        FileOutputStream outputStream = null;

        try {
            outputStream = new FileOutputStream(file);

            // 将 Bitmap 写入文件，压缩格式为 PNG，质量为 100（最高质量）
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
            Toast.makeText(context, "图片保存成功：" + file.getAbsolutePath(), Toast.LENGTH_LONG).show();

        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context, "保存失败：" + e.getMessage(), Toast.LENGTH_LONG).show();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void createViewFlutter(){
        //        ViewFlipper viewFlipper = findViewById(R.id.flipper);

//
//        ImageView imageView = new ImageView(this);
//        imageView.setLayoutParams(new ViewFlipper.LayoutParams(
//                ViewFlipper.LayoutParams.MATCH_PARENT,
//                ViewFlipper.LayoutParams.MATCH_PARENT));
//        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        imageView.setImageResource(R.drawable.a1);
//        viewFlipper.addView(imageView);
//
//        imageView = new ImageView(this);
//        imageView.setLayoutParams(new ViewFlipper.LayoutParams(
//                ViewFlipper.LayoutParams.MATCH_PARENT,
//                ViewFlipper.LayoutParams.MATCH_PARENT));
//        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        imageView.setImageResource(R.drawable.a2);
//        viewFlipper.addView(imageView);
//
//
//        viewFlipper.setFlipInterval(3000);
//        viewFlipper.setAutoStart(true);

    }
}
